<div id="tabsdetail">
        <div id="tab1" class="tabcontents">
          <form action="javascript:void(0)" id="check_order_form" method="post">
               <div class="hd">
                   <h2>hóa đơn nhập hàng</h2>
                   <div class="sub-form">
                       <label>Người lập  <input type="text" name="" id="order_user" value="<?php echo $_SESSION['ses_user']; ?>" size="28" /></label>
                   </div>
                   <div class="sub-form">
                   <?php $date = time();?>
                       <label>Ngày lập <input type="text" name="" id="order_date" value="<?php echo(date("d - m - Y",$date));  ?>" size="28" /></label>
                   </div>
                   <table>
                       <thead>
                           <tr>
                               <th>STT</th>
                               <th>Tên nguyên liệu</th>
                               <th width="10">Số lượng</th>
                               <th>Giá nhập</th>
                               <th>Thành tiền</th>
                               <th>Mua</th>
                           </tr>
                       </thead>
                       <tbody>
                           <tr>
                                <td>0</td>
                                <td>
                                    <select id="order_name">
                                        <option value="0" class="0">Chọn nguyên liệu</option>
                                        <?php
                                            if(isset($data['list_pro']) && $data['list_pro'] != NULL){
                                                $stt = 0;
                                                foreach($data['list_pro'] as $items){
                                                    $stt++;
                                                    echo '<option class="order_qtys_'.$stt.'" value="'.$items['manguyenlieu'].','.$items['dongia'].'">'.$items['tennguyenlieu'].'</option>';
                                                }
                                            }
                                        ?>
                                    </select>
                                </td>

                                <td class="quty">
                                    <input type="text" class="quyti" id="qty" name="s_quantity" value="1">
                                    <button class="minus" type="button"></button>
                                    <button class="plus" type="button"></button>
                                    
                                    <script type="text/javascript">
                                        //sô lượng giỏ hàng
                                        jQuery(document).ready(function($) {
                                            var quyti = $(".quyti").val();
                                        
                                            $(".minus").click(function(event) {
                                                quyti = parseInt(quyti) + 1;
                                                $(".quyti").val(quyti);
                                                
                                                pro_qty = $("#qty").val();
                                                pro_price = $(".pro_price").val();
                                                total = pro_qty * pro_price;
                                                $("#total_one").text(total);
                                            });
                                        
                                            $(".plus").click(function(event) {
                                                quyti = parseInt(quyti) - 1;
                                                if(quyti < 1){
                                                    alert("số lượng không thể nhỏ hơn 1");
                                                    $(".quyti").val(1);
                                                }else{
                                                    pro_qty = $("#qty").val();
                                                    pro_price = $(".pro_price").val();
                                                    total = pro_qty * pro_price;
                                                    $("#total_one").text(total);
                                                    $(".quyti").val(quyti);
                                                    
                                                }
                                            });
                                        });
    
                                    </script>
                                </td>
                                <td><input type="text" size="5" value="0" class="pro_price"></td>
                                <td><span id="total_one">0</span></td>
                                <td><input type="submit" id="cafe_buy" style="font-weight:bold" name="ok" value="Thêm" /></td>
                           </tr>
                           <tr>
                              <td style="border:none" colspan="6"></td>
                           </tr>
                           <tr>
                              <td style="border:none" colspan="6"><div class="cart_view"></div></td>
                           </tr>
                           <?php
							$total = 0;
							//debug($_SESSION['cart3']);
							if(isset($_SESSION['cart3']) && $_SESSION['cart3'] != NULL){
							$stt = 0;
							foreach($_SESSION['cart3'] as $key => $value){
							$stt ++;
                          ?>
                            <tr class="bachnx_all_row" style="padding-top:20px;">
                            <td><?php echo $stt; ?></td>
                            <td><?php echo $value['name']; ?></td>
                            <td><?php echo $value['qty']; ?></td>
                            <td><?php echo @number_format($value['price'])." VNĐ"; ?></td>
                            <td><?php $total_1 = ($value['price'] * $value['qty']);  echo @number_format($total_1)." VNĐ" ;?></td>
                            <td><a href="<?php echo base_url ;?>index.php?mod=shopping2&act=del&pid=<?php echo $value['id']; ?>&type=one" id="cafe_buy" style="font-weight:bold" onclick="return confirm('Bạn có muốn xóa không?');" />Xóa</a></td>
                            </tr>
                            <?php $total = $total + $total_1 ;?>
                        <?php } } ?>
                         <input type="hidden" name="total_cate_price" id="total_cate_price" value="<?php echo $total ?>" />
                       </tbody>
                   </table>

                   <script type="text/javascript">
                        $(document).ready(function(e){
                            $("#check_order_form").change(function(){
                                alls = $("#order_name").val();
                                pro_id = alls.substr(0,2);
                                pro_price = alls.substr(3,10);
                                //pro_id = $(".order_name").v("class");
                                //alert(pro_price); return false;
                                pro_qty = $("#qty").val();
                                pro_name = $(".order_qtys").html();
                                $(".pro_price").val(pro_price);
                                if(pro_qty == 0){
                                  alert("Vui lòng nhập số lượng lớn hơn 0");
                                  $("#qty").val("1");
                                  return false;
                                }
                                total = pro_qty * pro_price;
                                $("#total_one").text(total);
                                
                                $("#check_order_form").attr("action","index.php?mod=shopping2&act=add&pid="+pro_id);
                            });
                        });
                   </script>
                   
                   <p class="oder">Tổng tiền: <span id="total"><?php echo @number_format($total)." VNĐ" ;?></span></p><br>
                   <div class="notes">
                        <h3>Ghi chú</h3>
                        <textarea name="" id="cart_message" cols="" rows="5"></textarea>
                   </div>
                </div>
                </form>
                <ul class="add">
                    <!--li><a href="<?php echo base_url."index.php?mod=sales&act=add"?>">Thêm</a></li-->
                    <?php if(isset($_SESSION['cart3']) && $_SESSION['cart3'] != NULL){ ?>
                    <li><a href="javascript:void(0)" id="send_all">Lưu</a></li>
                    <?php } ?>
                    <li><a href="javascript:window.print();">In</a></li>
                    <li><a onclick="if(confirm('Bạn có chắc chắn muốn thoát ?')){return true;}else{return false;}" href="<?php echo base_url; ?>">Thoát</a></li>
                </ul>
        </div>
</div>

<script type="text/javascript">
  //Send cart
  $(document).ready(function(){
    $("#send_all").click(function(){
      cart_name   = $("#order_user").val();
      cart_message  = $("#cart_message").val();
      total       = $("#total_cate_price").val();
      val = "abc";
      $.ajax({
        "url" : "index.php?mod=shopping2&act=send",
        "type"  : "post",
        "data"  : "cart_name="+cart_name+"&cart_message="+cart_message+"&cart_total="+total+"&type="+val,
        "async" : "false",
        beforeSend : function(){
          $(".cart_view").html("Đang load dữ liệu ...");
        },
        success: function(results_cart){
            //$(".cart_view").html(results_cart);
            //return false;
            $(".cart_view").css("color","#639537").html("Đơn hàng của bạn đã được lưu lại !.");
            $(".bachnx_all_row").hide();
            $('body,html').animate({scrollTop:120},100);
            $("#total").text("0 VNĐ");
            $("#cart_message").val("");
        }
      })
      return false;
    });
  });
  
</script>